package com.ax.service.imple;


import javax.annotation.Resource;

import org.hibernate.SessionFactory;
import org.springframework.stereotype.Service;

import com.ax.pojo.TabContents;
import com.ax.service.TabContentsService;
import com.ax.utils.BaseDaoSupport;
import com.ax.utils.PageInfo;
@Service("tabContentsService")
public class TabContentsServiceImple implements TabContentsService {

	private BaseDaoSupport<TabContents> dao;
	
	@Resource(name="sessionFactory")
	public void setSessionFactort(SessionFactory sessionFactory){
		 dao=new BaseDaoSupport<TabContents>();
		 dao.setSessionFactory(sessionFactory);
	}
	
	public boolean delContents(TabContents tabContents) {
		boolean flag=true;
		try {
			dao.delete(tabContents);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public PageInfo findPageContents(int currentPageSize, String cound) {
		PageInfo pageInfo=new PageInfo();
		pageInfo.setData(dao.getPaginationData(cound, currentPageSize, pageInfo.getPageSize(), TabContents.class, null));
		pageInfo.setTotalCount(((Long)dao.getDataCount(TabContents.class, cound)).intValue());
		pageInfo.setCurPage(currentPageSize);
		return pageInfo;
	}

	public TabContents getContentsById(int id) {
		// TODO Auto-generated method stub
		return (TabContents)dao.getHibernateTemplate().get(TabContents.class, id);
	}

	public boolean saveContents(TabContents tabContents) {
		boolean flag=true;
		try {
			dao.save(tabContents);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

	public boolean updateContents(TabContents tabContents) {
		boolean flag=true;
		try {
			dao.update(tabContents);
		} catch (Exception e) {
			flag=false;
		}
		return flag;
	}

}
